import { Component, Injector } from '@angular/core';
import { IonicPage } from 'ionic-angular';
import { BasePage } from '../../basePage';
import { nailerService } from '../../../providers/nailerService';
import { PIC_URL } from "./../../../providers/Config";
import { StorageService } from './../../../providers/StorageService';

import { Observable } from 'rxjs/Observable';
import { Http, Response } from '@angular/http';
import "rxjs/add/operator/map";
/**
 * Generated class for the ApplyJoinShopPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-apply-join-shop',
  templateUrl: 'apply-join-shop.html',
})
export class ApplyJoinShopPage extends BasePage {
  showItemText: any;
  showItem: boolean;
  userinfo: any;
  picrooturl: string;
  yes:boolean=true;
  /**搜索店铺参数 */
  searchObj = {
    shop_id: '',
  }
  joinParam = {
    shop_id: null,
    user_id: null,
    time_stamp: ''
  }
  /*文章列表数据 */
  textList = [];
  flag: string = "0";

  constructor(injector: Injector, public stc: StorageService, public nailerservice: nailerService) {
    super(injector)
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ApplyJoinShopPage');
    this.picrooturl = PIC_URL;
    this.userinfo = this.stc.read('userinfo');
    console.log(this.userinfo.user_id);
    this.joinParam.user_id = this.userinfo.user_id
    this.timestampToTime()
  }

  dismissCLI() {
    this.viewCtrl.dismiss();
  }


  /**搜索店铺 */
  async searchArticle(e) {
    this.textList = [];
    this.joinParam.shop_id = null;
    console.log(this.searchObj);
    let res = await this.nailerservice.searchShopIDAPI(this.searchObj);
    console.log(res);
    if (res.error_code == 0) {
      this.textList.push(res.data);
      this.showItem = true;
      this.yes=true
    } else {
      this.showItem = false;
      this.yes=false
      this.showItemText = res.reason;
      // super.showToast(res.reason, 3000, 'top')
    }
    this.joinParam.shop_id = this.searchObj.shop_id;
    // console.log(this.joinParam)
  }
  /**申请加入美甲店 */
  async applyForShopArtistAPI() {
    console.log(this.joinParam)
    let res = await this.nailerservice.applyForShopArtistAPI(this.joinParam)
    console.log(res);
    super.showToast(res.reason, 3000, 'middle')
  }


  timestampToTime() {
    var timestamp = (new Date()).valueOf();
    console.log(timestamp)
    let date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    let Y = date.getFullYear() + '-';
    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    let D = date.getDate() + ' ';
    let h = date.getHours() + ':';
    let m = date.getMinutes() + ':';
    let s = date.getSeconds();
    let day = Y + M + D + h + m + s;
    console.log(day)
  }

  gotoShopD(){
    this.navCtrl.push('NaiShopDetailPage', { user_id2: this.joinParam.user_id, shop_id2: this.joinParam.shop_id })
  } /**跳转 到美甲店铺 */
  
}
